<?php

class AdminAuthorsController extends AdminAppController {
	
	public $name = 'Authors';
	
	public $uses = array('Author');
	
	public function create() {
		
		if( $this->request->is('ajax') ) {
			
			if( $this->Author->save( $this->request->data ) ) {
				$this->Author->recursive = 0;
				$author = $this->Author->read();
				$result = array(
					'status' => 1,
					'result' => $author
				);
			}
			else {
				$result = array(
					'status' => 0,
					'error' => $this->Author->validationErrors
				);
			}
			
			$this->header("Content-type: application/json");
			$this->autoRender = false;
			$this->autoLayout = false;
			echo json_encode( $result );
		}
		
	}
	
}